package com.jt.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

@Configuration
public class TokenConfig {
    
    
    /*
    * 配置令牌策略
    * JdbcTokenStore 存储到关系数据库
    * RedisTokenStore 存储到redis数据库
    * JwtTokenStroe 存储到客户端
    * 
    * */
    
    @Bean
    public TokenStore tokenStore(){
        return new JwtTokenStore(jwtAccessTokenConverter());
    }
    
    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter(){
        JwtAccessTokenConverter jwtAccessTokenConverter =
                new JwtAccessTokenConverter();
        
        jwtAccessTokenConverter.setSigningKey(STRING_KEY);
        
        return jwtAccessTokenConverter;
        //设置密钥
    }
    
    private final static String STRING_KEY="auth";
    
}
